<template>
	<view>
		<view class="ware-list">
			<view class="" v-if="!list.length" style="padding: 100rpx;">
				<view style="text-align: center;">
					无数据,请刷新重试
				</view>
			</view>
			<view class="ware-item" v-for="(item,index) in list" :key="index">
				<view class="" style="margin-bottom: 10rpx;">
					真实提单号:
					<text style="color: #333;margin-left: 10rpx;">{{item.code}}</text>
				</view>
				<view class="" style="margin-bottom: 10rpx;">
					系统提单号:
					<text style="color: #333;margin-left: 10rpx;">{{item.trade_code}}</text>
				</view>
				<view class="buttons" style="">
					<button @tap="openDialog(item.trade_code)" size="mini" type="primary">推送清关</button>
				</view>
			</view>

		</view>
		<view style="color: #666;text-align: center;padding-bottom: 20rpx;"
			v-if="list.length >= 10 && loadStatus == 'loadmore'">
			加载更多...
		</view>
		<view style="color: #666;text-align: center;padding-bottom: 20rpx;"
			v-if="list.length >= 10 && loadStatus == 'nomore'">
			无更多数据
		</view>
		<!-- 提示窗示例 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="error" cancelText="关闭" confirmText="确定" title="提示" content="确认推送清关?"
				@confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				list: [],
				pageloading: false,
				page: 1,
				limit: 10,
				loadStatus: 'loadmore',
				last_page: 0,
				index: 0,
				trade_code: ""
			}
		},
		onPullDownRefresh() {
			this.reloadList()
		},
		onReachBottom() {
			if (this.page > this.last_page) return this.loadStatus = 'nomore';
			this.loadStatus = 'loading';
			this.getlist()
		},
		onLoad() {
			this.getlist()
		},
		methods: {
			openDialog(trade_code) {
				this.trade_code = trade_code
				this.$refs.alertDialog.open()
			},
			dialogConfirm() {
				this.$api.admin({
					apiUrl: '/customs_affairs/pushRouter',
					param: {
						trade_code: this.trade_code
					}
				}).then((res) => {
					this.$t.message.toast(res.data.msg)
					this.reloadList()
				})
			},
			dialogClose() {
				this.$refs.alertDialog.close()
			},
			reloadList() {
				this.page = 1
				this.list = []
				this.loadStatus = 'loadmore'
				this.last_page = 0
				this.getlist()
			},
			getlist() {
				//获取权限
				this.$api.admin({
					apiUrl: '/customs_affairs/list',
					param: {
						page: this.page,
						limit: this.limit,
						type: 2
					}
				}).then((res) => {
					this.pageloading = false
					if (res.data.data.total) {
						this.last_page = Math.ceil(res.data.data.total / this.limit)
					}
					this.list = this.list.concat(res.data.data.data)
					this.page += 1
					console.log(this.list)
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.stopPullDownRefresh();
				})
			}
		}
	}
</script>

<style scoped lang='scss'>
	.ware-list {
		padding: 20rpx;

		.ware-item {
			border-bottom: 1rpx solid #e6e6e6;
			padding: 20rpx 0;
			color: #999;
			font-size: 30rpx;
			position: relative;

			.buttons {
				position: absolute;
				top: 30rpx;
				right: 0;
			}
		}
	}
</style>